package com.example.day20_zhongji.model;



import com.example.day20_zhongji.bean.ArticleBean;
import com.example.day20_zhongji.bean.BannerBean;
import com.example.day20_zhongji.not.ApiService;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class AritcleModel1  {
    public void aritcleModel(AritcleCallBack1 callBack){
        Retrofit build = new Retrofit.Builder()
                .baseUrl(ApiService.url)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        ApiService apiService = build.create(ApiService.class);
        apiService.getarticle().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ArticleBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ArticleBean articleBean) {
                        callBack.onSuccess(articleBean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        callBack.onFali(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
        apiService.getbanner().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BannerBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BannerBean bannerBean) {
                            callBack.onSuccess(bannerBean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        callBack.onFali1(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}